package com.practice.Optional语法糖;
import java.util.Optional;
/**
 * Created by IntelliJ IDEA2021.3
 * @Author: Tenghw
 * @Date: 2023/02/24  16:23
 * @Description: 映射
 */
public class Demo4 {
    public static void main(String[] args) {
        Student student = new Student("李四", 3);
        Optional<Student> os1 = Optional.ofNullable(student);
        // 如果student对象不为空，就加一岁；这里的e就是student
        Optional<Student> emp = os1.map(e ->
        {
            e.setAge(e.getAge() + 1);
            return e;
        });
        System.out.println(emp);
        System.out.println(emp.get());
    }
}
